#include<iostream>
#include<cstring>
using namespace std;

struct gas{
	int ot, nt, w;
}a[1010];

int o2, n2, n, dp[50][170];

int main() {
	cin >> o2 >> n2 >> n;
	memset(dp, 63, sizeof(dp));
	dp[0][0] = 0;
	for(int i=0; i<n; i++)	cin >> a[i].ot >> a[i].nt >> a[i].w;
	for(int i=0; i<n; i++) {
		for(int j=o2; j>=0; j--) {
			for(int k=n2; k>=0; k--) {
				int x = min(o2, j+a[i].ot);
				int y = min(n2, k+a[i].nt);
				dp[x][y] = min(dp[x][y], dp[j][k] + a[i].w);
			}
		}
	}
	cout << dp[o2][n2] << endl;
	return 0;
}